import { getPlayerData, getVegetableData, isPlayerExist } from '../l.js'
import puppeteer from "../../../lib/puppeteer/puppeteer.js";

export class Fs extends plugin {
    constructor() {
        super({
            name: '[Fs]蔬菜仓库',
            dsc: '蔬菜仓库',
            event: 'message',
            priority: 1,
            rule: [
                { reg: /^(#|\/)?蔬菜仓库$/, fnc: 'vegetableWarehouse' }
            ]
        })
    }
    async vegetableWarehouse(e) {
        const PLAYER_ID = e.user_id
        if (!isPlayerExist(PLAYER_ID)) {
            return e.reply(['无玩家信息，请发送[领取田地]喵~'])
        }
        const PLAYER_DATA = await getPlayerData(PLAYER_ID)
        const VEGETABLE_DATA = await getVegetableData()
        const VEGETABLE_LIST = Object.keys(PLAYER_DATA['Stash'])

        if (!VEGETABLE_LIST.length) return e.reply(['您没有任何作物喵~'])

        let info = []
        for (const VEGETABLE_NUMBER of VEGETABLE_LIST) {
            const CROP_DATA = VEGETABLE_DATA.find(c => c['name'] === VEGETABLE_NUMBER)
            info.push({
                name: VEGETABLE_NUMBER,
                number: PLAYER_DATA['Stash'][VEGETABLE_NUMBER]['number'],
                expectedAvailabilityOfFunds: CROP_DATA['salePrice'] * PLAYER_DATA['Stash'][VEGETABLE_NUMBER]['number']
            })
        }
        const image = await puppeteer.screenshot('蔬菜仓库', {
            tplFile: 'plugins/Farming-Simulator/resources/html/vegetableWarehouse.html',
            info,
        })
        return e.reply([image])
    }
}